%%%-------------------------------------------------------------------
%%% File    : pipe.hrl
%%% Author  :  <vjache>
%%% Description : TODO: Add description to pipe
%%%
%%% Created : 23.03.2009
%%%-------------------------------------------------------------------

%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Record: iter 
%% Description: Iterator descriptor. It used to define custom iterator
%% 				for using iteration logic defined at 'iter.erl'.
%% Attributes:	param - arbitrary term passed to open fun
%%				open_fun - fun to create initial state of iterator: 
%%					fun(Param)->State.
%%				next_fun - fun to retrieve next item in iterator:
%%					fun(State)->{NewState,Item}|{NewState,'$EOF'}if exhausted.
%%				close_fun - fun to release resources of iterator if any:
%%					fun(State)->ok.
%%--------------------------------------------------------------------
-record(pipe,{
			  id=make_ref(),
			  param,
			  open_fun,
			  push_fun,
			  flush_fun,
			  close_fun,
			  next_pipe=terminal}).

-record(folder,
		{
		 open_fun=fun()-> [] end,%% Returns a new initial accumulator
		 fold_fun=fun(Item,AccIn)-> [Item|AccIn] end,%% Folds Item with AccIn and retuns new one
		 close_fun=fun(_Acc)-> ok end,%% Releases resources of folder if any
		 result_fun=fun(Acc)-> [Acc] end,%% Converts accumulator to result before pass to next pipe
		 capacity=10 %% Returns folder capacity (-1 denotes Infinity). If exhausted then accumulated value pass to next pipe and folder destroyed.
		}).

-ifndef(EOF).
-define(EOF,'$EOF').
-endif.

-ifndef(REJECT_REC).
-define(REJECT_REC,'$reject').
-endif.

-define(PIPE_SENDER_MSG(SenderSign,SenderPid,Value),
		{'$PSM',SenderSign,SenderPid,Value}).
-define(PIPE_SENDER_MSG_CONFIRM,{'$PSM',ok}).

-define(IS_PIPE(P), is_record(P,pipe)).


